<template>
  <div class="search-result">
    <van-list
      class="search-list"
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <van-cell
        v-for="(item, index) in lists"
        :key="index"
        :title="item.name"
        :value="item.ar[0].name"
        :to="{
          name: 'play',
          params: {
            playid: item.id,
          },
        }"
      />
    </van-list>
  </div>
</template>
<script>
import { getSearch } from "@/api/search.js";
export default {
  props: {
    searchText: {
      type: String,
      required: true,
    },
  },
  data() {
    return {
      lists: [],
      loading: false,
      finished: false,
      page: 1, //页数
      pageNum: 10, //一页数量
      songid:[]
    };
  },
  methods: {
    //获取搜索结果
    async onLoad() {
      const { data } = await getSearch({
        keywords: this.searchText,
        limit: this.pageNum,
        offset: (this.page - 1) * this.pageNum,
      });

      const num = data.result.songs;
      this.lists.push(...num);

  //获取歌手姓名
 
          

      //关闭loading
      this.loading = false;

      if ([...num].length) {
        this.page++;
      } else {
        this.finished = true;
      }

      
    },
  },
};
</script>

<style lang="less" scoped>
.search-result {
  position: fixed;
  left: 0;
  right: 0;
  top: 54px;
  bottom: 0;
  overflow-y: auto;
}
</style>